package com.story.api.moduler.option.controller;

import com.story.api.common.result.ServerResponse;
import com.story.api.moduler.option.dto.FeedbackDto;
import com.story.api.moduler.option.service.FeedbackService;
import com.story.api.moduler.option.service.SocialContactService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Administrator
 * @decription 意见反馈和社交联系
 * @Date 2017-12-15 11:12
 */
@RestController
@RequestMapping(value = "/child")
public class OptionController {

    private static final Logger log  = LoggerFactory.getLogger(OptionController.class);

    @Autowired
    private FeedbackService feedbackService;

    @Autowired
    private SocialContactService socialContactService;

    /**
     * 提交反馈意见
     * @param feedbackDto
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/optionFeedback",method = RequestMethod.POST)
    public ServerResponse feedback(@RequestBody @Valid FeedbackDto feedbackDto, BindingResult bindingResult) {
        if(bindingResult.hasErrors()) {
            return ServerResponse.getErrorMessage(bindingResult.getFieldError().getDefaultMessage());
        }
        return feedbackService.submitFeedback(feedbackDto);
    }

    /**
     * 获得社交联系方式
     * @return
     */
    @RequestMapping(value = "/getSocialContact",method = RequestMethod.POST)
    public ServerResponse getSocialContact() {
        return socialContactService.getSocicalContact();
    }

}
